package com.henanuniversity.controller;

import com.henanuniversity.po.User;
import com.henanuniversity.service.UserService;
import com.henanuniversity.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserController {
    public Object saveUser(HttpServletRequest request, HttpServletResponse response){
        String userId=request.getParameter("userId");
        String password=request.getParameter("password");
        String userName=request.getParameter("userName");
        Integer userSex=Integer.parseInt(request.getParameter("userSex"));
        User user=new User(userId,password,userName,userSex,null);
        UserService service=new UserServiceImpl();
        int i = service.saveUser(user);
        return i;
    }

    public Object getUserByIdByPassword(HttpServletRequest request, HttpServletResponse response){
        String userId=request.getParameter("userId");
        String password=request.getParameter("password");
        UserService service=new UserServiceImpl();
        User user = service.getUserByIdByPass(userId, password);
        if(user!=null){
            request.getSession().setAttribute("user",user);
        }
        return user;
    }

    public Object getUserById(HttpServletRequest request, HttpServletResponse response){
        String userId=request.getParameter("userId");
        UserService service=new UserServiceImpl();
        User user = service.getUserById(userId);
        return user;
    }
}
